home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / tclX-6.4 / buildidx.tcl < prev    next >
Encoding:
Text File  |  1992-12-17  |  3.1 KB  |  100 lines

  1. #
  2. # buildidx.tcl --
  3. #
  4. # Code to build Tcl package library. Defines the proc `buildpackageindex'.
  5. #------------------------------------------------------------------------------
  6. # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
  7. #
  8. # Permission to use, copy, modify, and distribute this software and its
  9. # documentation for any purpose and without fee is hereby granted, provided
  10. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  11. # Mark Diekhans make no representations about the suitability of this
  12. # software for any purpose.  It is provided "as is" without express or
  13. # implied warranty.
  14. #------------------------------------------------------------------------------
  15. # $Id: buildidx.tcl,v 2.0 1992/10/16 04:51:38 markd Rel $
  16. #------------------------------------------------------------------------------
  17. #
  18.  
  19. proc TCHSH:PutLibLine {outfp package where endwhere autoprocs} {
  20.     puts $outfp [concat $package $where [expr {$endwhere - $where - 1}] \
  21.                         $autoprocs]
  22. }
  23.  
  24. proc TCLSH:CreateLibIndex {libName} {
  25.  
  26.     if {[file extension $libName] != ".tlib"} {
  27.         error "Package library `$libName' does not have the extension `.tlib'"}
  28.     set idxName "[file root $libName].tndx"
  29.  
  30.     unlink -nocomplain $idxName
  31.     set libFH [open $libName r]
  32.     set idxFH [open $idxName w]
  33.  
  34.     set contectHdl [scancontext create]
  35.  
  36.     scanmatch $contectHdl "^#@package: " {
  37.         set size [llength $matchInfo(line)]
  38.         if {$size < 2} {
  39.             error [format "invalid package header \"%s\"" $matchInfo(line)]
  40.         }
  41.         if $inPackage {
  42.             TCHSH:PutLibLine $idxFH $pkgDefName $pkgDefWhere \
  43.                              $matchInfo(offset) $pkgDefProcs
  44.         }
  45.         set pkgDefName   [lindex $matchInfo(line) 1]
  46.         set pkgDefWhere  [tell $matchInfo(handle)]
  47.         set pkgDefProcs  [lrange $matchInfo(line) 2 end]
  48.         set inPackage 1
  49.     }
  50.  
  51.     scanmatch $contectHdl "^#@packend" {
  52.         if !$inPackage {
  53.             error "#@packend without #@package in $libName
  54.         }
  55.         TCHSH:PutLibLine $idxFH $pkgDefName $pkgDefWhere $matchInfo(offset) \
  56.                          $pkgDefProcs
  57.         set inPackage 0
  58.     }
  59.  
  60.     set inPackage 0
  61.     if {[catch {
  62.         scanfile $contectHdl $libFH
  63.        } msg] != 0} {
  64.        global errorInfo errorCode
  65.        close libFH
  66.        close idxFH
  67.        error $msg $errorInfo $errorCode
  68.     }
  69.     if {![info exists pkgDefName]} {
  70.         error "No #@package definitions found in $libName"
  71.     }
  72.     if $inPackage {
  73.         TCHSH:PutLibLine $idxFH $pkgDefName $pkgDefWhere [tell $libFH] \
  74.                          $pkgDefProcs
  75.     }
  76.     close $libFH
  77.     close $idxFH
  78.     
  79.     scancontext delete $contectHdl
  80.  
  81.     # Set mode and ownership of the index to be the same as the library.
  82.  
  83.     file stat $libName statInfo
  84.     chmod $statInfo(mode) $idxName
  85.     chown [list $statInfo(uid) $statInfo(gid)] $idxName
  86.  
  87. }
  88.  
  89. proc buildpackageindex {libfile} {
  90.  
  91.     set status [catch {TCLSH:CreateLibIndex $libfile} errmsg]
  92.     if {$status != 0} {
  93.         global errorInfo errorCode
  94.         error "building package index for `$libfile' failed: $errmsg" \
  95.               $errorInfo $errorCode
  96.     }
  97. }
  98.  
  99.